package com.dcd.controller;

import com.dcd.pojo.Follow_user;
import com.dcd.service.Follow_userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class Follow_userController {

    @Autowired
    private Follow_userService fs;

    /**
     * 查询所有关注的用户(根据登录用户id查询)
     * @param follow_user_id 登录用户id
     * @return
     */
    @RequestMapping("/select_Follow_user")
    public List<Follow_user> select_Follow_user(@RequestParam int follow_user_id){
        return fs.selectFollowUser(follow_user_id);
    }

    /**
     * 根据登入id查询用户详情
     * @param user_id 用户登入id
     * @return
     */
    @RequestMapping("/select_ById")
    public Follow_user select_ById(@RequestParam int user_id){
        return fs.selectById(user_id);
    }

    /**
     * 根据被关注id查询粉丝数
     * @param cover_id 被关注id
     * @return
     */
    @RequestMapping("/select_By_CoverId")
    public Follow_user select_By_CoverId(@RequestParam int cover_id){
        return fs.selectByCoverId(cover_id);
    }



    /**
     * 根据条件添加，取消关注
     * @param follow_user 关注用户表的对象
     * @return
     */
    @RequestMapping("/insert_or_delete_follow_user_id")
    public String insert_or_delete_follow_user_id(@RequestBody Follow_user follow_user,@RequestParam String type){
        if(type.equals("insert")){
            return "{\"result\":\""+fs.addFollowUser(follow_user)+"\"}";
        }
        return "{\"result\":\""+fs.deleteFollowUser(follow_user)+"\"}";
    }

    /**
     * 查询用户是否关注指定用户
     * @param follow_user
     * @return
     */
    @RequestMapping("/select_user_follow_user")
    public String select_user_follow_user(@RequestBody Follow_user follow_user){
        return "{\"result\":\"" + fs.select_user_follow_user(follow_user) + "\"}";

    }
}
